#ifndef TPA626_H_
#define TPA626_H_

#include "stdint.h"
#include "myiic.h"

// 建议改成直接用7位地址，然后自动加R/W位
#define TPA626_ADDR_WR     0x40
#define TPA626_ADDR_RD     0x41

#define I2C_WRITE(addr)     ((addr << 1) | 0x00)
#define I2C_READ(addr)      ((addr << 1) | 0x01)

#define Config_Reg              0x00
#define Shunt_V_Reg             0x01
#define Bus_V_Reg               0x02
#define Power_Reg               0x03
#define Current_Reg             0x04
#define Calib_Reg               0x05
#define Mask_En_Reg             0x06
#define Alert_Reg               0x07
#define Man_ID_Reg              0xFE  // 0x5449
#define ID_Reg                  0xFF  // 0x2260

typedef struct {
    uint16_t VD1_Bus_V;
    uint16_t VD1_Curent;
    uint16_t VD1_Power;
    uint16_t VD2_Bus_V;
    uint16_t VD2_Curent;
    uint16_t VD2_Power;
} TPA626;

extern TPA626 sTPA626;

void TPA626_Init(_myiic_t *iic);
uint16_t TPA626_Read2Byte(_myiic_t *iic, uint8_t reg_addr, uint8_t VDx);
uint8_t  TPA626_Write2Byte(_myiic_t *iic, uint8_t reg_addr, uint16_t reg_data, uint8_t VDx);

#endif
